<template>
  <div class="full_Return_Details" :style="{ '--bgdetail': `${infoData.background_color}` }">
    <c-title :hide="false" :text="infoData.name"></c-title>
    <div class="headImg">
      <img :src="infoData.top_pic_url" alt="" />
    </div>
    <div class="contenBox" v-if="infoData">
      <div class="event_countdown" v-if="nowTime < infoData.end_time">
        {{ nowTime > infoData.start_time ? "距离活动结束" : "距离活动开始" }}：<van-count-down
          :time="nowTime > infoData.start_time ? (infoData.end_time - nowTime) * 1000 : (infoData.start_time - nowTime) * 1000"
        >
          <template #default="timeData">
            <span class="block">{{ timeData.days < 10 ? "0" + timeData.days : timeData.days }}</span>
            <span class="colon">天</span>
            <span class="block">{{ timeData.hours < 10 ? "0" + timeData.hours : timeData.hours }}</span>
            <span class="colon">时</span>
            <span class="block">{{ timeData.minutes < 10 ? "0" + timeData.minutes : timeData.minutes }}</span>
            <span class="colon">分</span>
            <span class="block">{{ timeData.seconds < 10 ? "0" + timeData.seconds : timeData.seconds }}</span>
            <span class="colon">秒</span>
          </template>
        </van-count-down>
      </div>
      <div class="event_countdown" v-else>活动已结束</div>
      <div class="reward">
        <div class="reward_top">
          <div class="reward_top_left">我的奖励</div>
          <div class="reward_top_right">
            预计奖励金额:<span class="price">{{ $i18n.t("money") }}{{ infoData.expect_reward_amount }}</span>
          </div>
        </div>
        <template v-if="infoData.type != 2">
          <div class="statistics">
            <div class="statistics_lis">
              <div class="count">{{ infoData.full_goods_count }}</div>
              <div class="txt">销售件数（预计）</div>
            </div>
            <div class="statistics_lis">
              <div class="count">{{ $i18n.t("money") }}{{ infoData.settle_reward_amount }}</div>
              <div class="txt">奖励（已获得）</div>
            </div>
          </div>
          <div class="Progress">
            <div class="line">
              <div class="line_l">额外奖励（预计）</div>
              <div class="line_r">
                <div class="txt" v-for="(item, index) in infoData.step_list" :key="index">{{ $i18n.t("money") }}{{ item.reward_amount }}</div>
              </div>
            </div>
            <div class="progress_line">
              <div class="prog">
                <div class="round" v-for="(items, index) in infoData.step_list" :key="index">
                  <div
                    class="round_l"
                    :class="{ round_l_w: infoData.step_list.length > 1 ? (infoData.step_list[index + 1] ? infoData.step_list[index + 1].is_reward : '') : items.is_reward }"
                    v-if="items.is_reward"
                  ></div>
                  <div class="circle"></div>
                </div>
              </div>
            </div>
            <div class="line">
              <div class="line_l">销售件数（预计）</div>
              <div class="line_r">
                <div class="txt" v-for="(item, index) in infoData.step_list" :key="index">{{ item.goods_count }}件</div>
              </div>
            </div>
          </div>
        </template>
        <template v-else>
          <div class="statistics">
            <div class="statistics_lis">
              <div class="count">{{ $i18n.t("money") }}{{ infoData.rank_sale_amount }}</div>
              <div class="txt">TOP{{ infoData.rank }}销售（预计）</div>
            </div>
          </div>
        </template>
      </div>
      <div class="Activity_products">
        <div class="Activity_products_top">
          <div class="Activity_products_top_title">活动商品</div>
          <div class="Activity_products_top_more" @click="tolink(item, 'full_Return_Details_list', { id: $route.params.id }, { name: infoData.name })">
            查看更多<i class="iconfont icon-icon_more1"></i>
          </div>
        </div>
        <div class="Activity_products_good" @click="tolink(item, 'goods')" v-for="(item, index) in goodList" :key="index">
          <div class="Activity_products_good_l">
            <img :src="item.thumb" alt="" />
          </div>
          <div class="Activity_products_good_r">
            <div class="Activity_products_good_r_d">
              <div class="title van-ellipsis">{{ item.title }}</div>
              <div class="price">{{ $i18n.t("money") }}{{ item.price }}</div>
            </div>
            <div class="iconfont icon-icon_more1"></div>
          </div>
        </div>
      </div>
      
      
      <template v-if="infoData.type == 2">
        <div class="rankingBox">
          <div class="rankingTop">
            <div class="txt rank">排名</div>
            <div class="txt sid">店长ID</div>
            <div class="txt income">销售额</div>
            <div class="txt au">预计总奖励金额</div>
          </div>
          <div class="rankingTop line">
            <div class="txt rank first">{{ infoData.rank }}</div>
            <div class="txt sid">
              <img :src="infoData.member.avatar_image" alt="" />
              <div class="name van-ellipsis first">{{ infoData.member.nickname }}</div>
            </div>
            <div class="txt income van-ellipsis first">{{ $i18n.t("money") }}{{ infoData.rank_sale_amount }}</div>
            <div class="txt au van-ellipsis first">{{ $i18n.t("money") }}{{ infoData.expect_reward_amount }}</div>
          </div>
          <template v-for="item in rankList">
            <div class="rankingTop line" :key="item.id" v-if="item.rank != infoData.rank">
              <div class="txt rank">{{ item.rank }}</div>
              <div class="txt sid" v-if="item.has_one_member">
                <img :src="item.has_one_member.avatar_image" alt="" />
                <div class="name van-ellipsis">{{ item.has_one_member.nickname }}</div>
              </div>
              <div class="txt income van-ellipsis">{{ $i18n.t("money") }}{{ item.amount }}</div>
              <div class="txt au van-ellipsis">{{ $i18n.t("money") }}{{ item.reward_amount }}</div>
            </div>
          </template>
        </div>
      </template>
      <div class="bgImg" v-if="infoData.back_pic_url">
        <img :src="infoData.back_pic_url" alt="" />
      </div>
      <div class="desc" v-if="infoData.detail_desc">
        <div class="desc_title">活动说明</div>
        <div v-html="infoData.detail_desc" class="desc_conten"></div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      infoData: [],
      nowTime: "",
      goodList: [],
      rankList: [],
      // 活动商品最后页数
      goodPage: {
        page: 1,
        total_page: 0
      },
      rankPage: {
        page: 1,
        total_page: 0
      }
    };
  },
  activated() {
    this.nowTime = Date.parse(new Date()) / 1000;
    this.getData();
  },
  methods: {
    tolink(item, key, params = {}, query = {}) {
      if (key == "goods") {
        this.$router.push(this.fun.getUrl(key, { id: item.id }));
        return;
      }
      this.$router.push(this.fun.getUrl(key, params, query));
    },
    async getData() {
      let { data, msg, result } = await $http.post("plugin.cloud-shop.frontend.activity.detail", { id: this.$route.params.id }, "");
      if (result) {
        this.infoData = data;
        this.fun.setWXTitle(data.name);
        this.getGoodList();
        if (data.type == 2) {
          this.getRank();
        }
      } else {
        this.$toast(msg);
      }
    },
    async getRank() {
      let { data, msg, result } = await $http.post("plugin.cloud-shop.frontend.activity.rankList", { id: this.$route.params.id }, "");
      if (result) {
        this.rankList = data.data;
        this.rankPage.total_page = data.last_page;
      } else {
        this.$toast(msg);
      }
    },
    async getGoodList() {
      let { data, msg, result } = await $http.post("plugin.cloud-shop.frontend.activity.goodsList", { id: this.$route.params.id }, "");
      if (result) {
        console.log(data);
        this.goodList = data.data;
        this.goodPage.total_page = data.last_page;
      } else {
        this.$toast(msg);
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.full_Return_Details {
  padding-bottom: 1rem;
  background: var(--bgdetail);
}
.headImg {
  width: 100%;
  background: #fff;
  img {
    width: 100%;
    height: auto;
    display: block;
  }
}
.contenBox {
  margin: 0 0.75rem;
  margin-top: 0.63rem;
  .rankingBox {
    margin-top: 0.63rem;
    border-radius: 0.5rem;
    background: #fff;
    padding-bottom: 0.5rem;
    .rankingTop {
      height: 2.5rem;
      display: flex;
      border-radius: 0.5rem 0.5rem 0 0;
      background: #fef1f1;
      display: flex;
      align-items: center;
      padding: 0 0.3rem;
      box-sizing: border-box;
      .first {
        color: #f15353 !important;
      }
      .txt {
        font-weight: 500;
        font-size: 0.81rem;
        text-align: left;
        overflow: hidden;
      }
      .rank {
        width: 3.47rem;
        text-align: center;
      }
      .sid {
        width: 7.06rem;
        text-align: left;
        overflow: hidden;
        display: flex;
        align-items: center;
        img {
          width: 1.25rem;
          height: 1.25rem;
          background: #d6d6dc;
          margin: 0;
          border-radius: 50%;
        }
        .name {
          font-size: 0.81rem;
          margin-left: 0.3rem;
        }
      }
      .income {
        width: 5rem;
        text-align: left;
      }
      .au {
        flex: 1;
      }
    }
    .line {
      background: #fff;
      border-radius: 0;
      border-bottom: 1px solid #f0f0f1;
      padding: 0;
      margin: 0 0.3rem;
    }
    .line:last-child {
      border-bottom: 0;
    }
  }
  .desc {
    box-sizing: border-box;
    margin-top: 0.63rem;
    padding: 0.94rem 0.63rem;
    border-radius: 0.5rem;
    background: #fff;
    .desc_conten {
      text-align: left;
    }
    .desc_title {
      text-align: left;
      font-weight: bold;
      font-size: 0.94rem;
      margin-bottom: 0.63rem;
    }
  }
  .bgImg {
    margin-top: 0.63rem;
    width: 100%;
    min-height: 11.25rem;
    border-radius: 0.5rem;
    background: #ffffff;
    img {
      width: 100%;
      height: auto;
      display: block;
      border-radius: 0.5rem;
    }
  }
  .Activity_products {
    margin-top: 0.63rem;
    background: #ffffff;
    border-radius: 0.5rem;
    padding: 0.94rem 0.63rem;
    box-sizing: border-box;
    .Activity_products_good {
      background: #f5f5f5;
      border-radius: 0.63rem;
      padding: 0.31rem;
      box-sizing: border-box;
      display: flex;
      justify-content: space-between;
      margin-bottom: 0.63rem;
      .Activity_products_good_r {
        flex: 1;
        display: flex;
        justify-content: space-between;
        align-items: center;
        overflow: hidden;
        .Activity_products_good_r_d {
          text-align: left;
          overflow: hidden;
          flex: 1;
          .title {
            font-weight: 500;
            font-size: 0.88rem;
            color: #00001c;
            text-align: left;
          }
          .price {
            margin-top: 0.78rem;
            font-weight: 500;
            font-size: 0.94rem;
            color: #f15353;
          }
        }
        .icon-icon_more1 {
          font-size: 0.9rem;
          color: #aaaab3;
        }
      }
      .Activity_products_good_l {
        flex-shrink: 0;
        width: 3.63rem;
        height: 3.63rem;
        background: #f0f0f1;
        border-radius: 0.5rem;
        margin-right: 0.94rem;
        img {
          width: 100%;
          height: 100%;
          border-radius: 0.5rem;
        }
      }
    }
    .Activity_products_good:last-child {
      margin-bottom: 0;
    }
    .Activity_products_top {
      display: flex;
      justify-content: space-between;
      margin-bottom: 0.88rem;

      .Activity_products_top_title {
        font-weight: bold;
        font-size: 0.94rem;
      }
      .Activity_products_top_more {
        font-size: 0.81rem;
        color: #999999;
        .icon-icon_more1 {
          margin-left: 0.3rem;
          color: #999999;
          font-size: 0.8rem;
        }
      }
    }
  }
  .reward {
    margin-top: 0.63rem;
    padding: 0.94rem 0.75rem;
    background: #ffffff;
    border-radius: 0.5rem;
    .Progress {
      margin-top: 0.63rem;
      background: rgba(241, 83, 83, 0.06);
      padding: 0.78rem 0.63rem;
      padding-right: 0.78rem 0.63rem;
      border-radius: 0.5rem;
      .progress_line {
        padding-left: 6.5rem;
        height: 0.19rem;
        border-radius: 0.09rem;
        margin: 0.5rem 0;
        .prog {
          width: 100%;
          height: 100%;
          background: #fbc4c4;
          display: flex;
          justify-content: space-around;
          align-items: center;
          .round {
            flex: 1;
            display: flex;
            justify-content: center;
            position: relative;
            .circle {
              width: 0.5rem;
              height: 0.5rem;
              background: #ffffff;
              border: 2px solid rgba(241, 83, 83, 0.3);
              border-radius: 50%;
              position: relative;
            }
          }
          .round_l {
            width: 50%;
            height: 0.19rem;
            position: absolute;
            left: 0;
            top: 0.12rem;
            background: red;
            border-radius: 0.09rem;
          }
          .round_l_w {
            width: 100% !important;
          }
        }
      }
      .line {
        display: flex;
        align-items: center;
        font-size: 0.81rem;
        .line_l {
          flex-shrink: 0;
        }
        .line_r {
          flex: 1;
          display: flex;
          justify-content: space-around;
          align-items: center;
          .txt {
            width: calc(100% / 3);
            font-weight: 500;
            font-size: 0.81rem;
            color: #00001c;
          }
        }
      }
    }
    .statistics {
      height: 4.25rem;
      background: rgba(241, 83, 83, 0.06);
      border-radius: 0.63rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .statistics_lis {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        .count {
          font-weight: 500;
          font-size: 1.13rem;
          color: #f15353;
        }
        .txt {
          font-size: 0.75rem;
          color: #00001c;
        }
      }
    }
    .reward_top {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 0.88rem;
      .reward_top_left {
        font-weight: bold;
        font-size: 0.94rem;
        color: #00001c;
      }
      .reward_top_right {
        font-weight: 500;
        font-size: 0.88rem;
        .price {
          color: #f15353;
        }
      }
    }
  }
  .event_countdown {
    height: 3rem;
    background: #ffffff;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    .block {
      font-weight: 500;
      font-size: 0.88rem;
      color: #f15353;
      padding: 0.22rem;
      border-radius: 0.25rem;
      margin-right: 0.28rem;
      background: rgba(241, 83, 83, 0.1);
    }
    .colon {
      font-size: 0.94rem;
      color: #00001c;
      margin-right: 0.23rem;
    }
  }
}
</style>
